package com.four.project.controller;


import com.four.project.pojo.Teacher;
import com.four.project.pojo.TeacherResp;
import com.four.project.service.TeacherService;
import com.four.project.utils.UploadUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@CrossOrigin
public class TeacherController {
    /*
     *@author syk
     *@version 1.0
     *@since 2020-07-07 14:17
     */
    @Autowired
    TeacherService teacherService;
    @Autowired
    UploadUtils uploadUtils;

    @RequiresPermissions(value = {"add"})
    @PostMapping("/addTeacher")
    public String insert(@RequestBody Teacher teacher){
        return teacherService.insert(teacher);
    }

    @RequestMapping("/upload")
    public String upload(@RequestParam("file") MultipartFile multipartFile){
        return uploadUtils.upload(multipartFile);
    }

    @RequiresPermissions(value = {"query"})
    @RequestMapping("/findAllTeacher/{page}/{size}")
    public TeacherResp findAll(@PathVariable("page")Integer page, @PathVariable("size")Integer size){
        return teacherService.findAll(page,size);
    }

    @RequiresPermissions(value = {"update"})
    @PostMapping("/updateTeacher")
    public String update(@RequestBody Teacher teacher){
        Teacher resp = teacherService.updateTeacher(teacher);
        if (resp!=null){
            return "success";
        }else{
            return "error";
        }
    }

    @RequiresPermissions(value = {"delete"})
    @DeleteMapping("/deleteTeacherbyid/{id}")
    public void deleteCustom(@PathVariable("id") Integer id){
        teacherService.deleteById(id);
    }

    //修改我的信息
    @RequestMapping("/updatemymessage")
    public Integer updateMyMessage(Teacher teacher){
        Integer integer = teacherService.updateMyMessage(teacher);
        System.out.println(integer);
        return integer;
    }


}



